package cn.petplatform.globalexception;

import cn.petplatform.dto.ResponseDto;
import cn.petplatform.petback.exceptions.DataTransformException;
import cn.petplatform.petback.exceptions.PublishPetException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author LNL
 * @date 2021/5/15 17:11
 */
@ControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(DataTransformException.class)
    @ResponseBody
    public ResponseDto handleDataTransformException(DataTransformException e) {
        ResponseDto responseDto = new ResponseDto("1001",e.getMsg());
        return responseDto;
    }
    @ExceptionHandler(PublishPetException.class)
    @ResponseBody
    public ResponseDto handlePublishPetException(PublishPetException e) {
        ResponseDto responseDto = new ResponseDto("1001",e.getMsg());
        return responseDto;
    }


    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ResponseDto handleRuntimeException(RuntimeException e) {
        e.printStackTrace();
        ResponseDto responseDto = new ResponseDto("1001",e.getMessage());
        return responseDto;
    }

}
